'use strict'

class userlist {

    constructor() {
        //param默认就是/:id，若要改变路由，则可以设置此属性，比如设置为/:name
        this.param = '/'
    }

    async get(c) {
        let ret = await c.service.psql.query(`select * from elegant_user`)
        c.status(200).send(ret.rows);
    }

    async delete(c) {
        if (!c.body.isRows) {
            var id = c.body.id
            console.log(id)
            if (id) {
                let ret = await c.service.psql.query(`delete from elegant_user where user_id like '${id}'`)
                console.log(ret)
                c.send('已删除')

            } else {
                c.send('删除失败')
            }
        } else {
            var idArr = c.body.idArr
            console.log(idArr)
            for (let i = 0; i < idArr.length; i++) {
                let ret = await c.service.psql.query(`delete from elegant_user where user_id like '${idArr[i]}'`)
                console.log(ret)
            }
            c.send('complete')
        }
    }
}

module.exports = userlist
